<?php
class Crypt{
	
	const CRYPT_COST = 10;
	
	static public function generateHash( $password ){
		$salt = hash('sha256', openssl_random_pseudo_bytes(22) . $password );
		$salt = sprintf( "$2a$%02d$", self::CRYPT_COST ) . $salt;
		return crypt( $password, $salt );
	}
	
	static public function generateToken( $username ){
		$salt = hash('sha256', openssl_random_pseudo_bytes(22) . $username . date( 'Y-m-d H:i:m' ) );
		$salt = sprintf( "$2a$%02d$", self::CRYPT_COST ) . $salt;
		return crypt( $username, $salt );
	}
	
}